

/* 
处理异步假报错
? 是undef 就返回undef
|| 是undef 就返回 || 后面的
*/

import { requestDetail } from '@/api'
const state = {
  detailInfo: {}
}
const mutations = {
  SET_DETAILINFOR_STATE(state, value) {
    state.detailInfo = value
  }
}
const actions = {
  async getDetail({ commit }, skuId) {
    const result = await requestDetail(skuId)
    commit("SET_DETAILINFOR_STATE", result)
  }
}

const getters = {

  categoryView(state) {
    return state.detailInfo.categoryView || {}
  },

  spuSaleAttrList(state) {
    return state.detailInfo.spuSaleAttrList || []
  },
  skuInfo(state) {
    return state.detailInfo.skuInfo || {}
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
}